package com.richpath.animator;

import android.animation.TypeEvaluator;

import androidx.core.graphics.PathParser;

/**
 * Created by tarek on 7/14/17.
 */

public class PathEvaluator implements TypeEvaluator<PathParser.PathDataNode[]> {

    private PathParser.PathDataNode[] evaluatedNodes;

    @Override
    public PathParser.PathDataNode[] evaluate(float fraction, PathParser.PathDataNode[] startPathDataNodes, PathParser.PathDataNode[] endPathDataNodes) {

        if (evaluatedNodes == null) {
            evaluatedNodes = PathParser.deepCopyNodes(startPathDataNodes);
        }

        for (int i = 0; i < startPathDataNodes.length; i++) {
            for (int j = 0; j < startPathDataNodes[i].mParams.length; j++) {
                float startFloat = startPathDataNodes[i].mParams[j];
                float value = startFloat + fraction * (endPathDataNodes[i].mParams[j] - startFloat);
                evaluatedNodes[i].mParams[j] = value;
            }
        }

        return evaluatedNodes;
    }


}
